package org.pine.start.interceptor;

import net.sf.jsqlparser.expression.Expression;
import org.pine.common.annotation.DataPermission;
import org.pine.common.enums.DbDataScopeEnum;
import org.springframework.beans.factory.InitializingBean;

/**
 * 角色数据权限处理器-监听器
 *
 * @author pine manage
 * @since 2024-09-26
 */
public interface ProcessWhereExpressionListener extends InitializingBean {

    /**
     * 处理where条件
     *
     * @param where          where语句
     * @param dataPermission 权限注解
     * @param mainTableName  主表名/别名
     */
    Expression process(Expression where, DataPermission dataPermission, String mainTableName);

    /**
     * 获取数据权限范围
     *
     * @return 数据权限范围
     */
    DbDataScopeEnum getDataScope();

    @Override
    default void afterPropertiesSet() {
        DbDataScopeEnum dataScope = getDataScope();
        if (dataScope != null) {
            RoleCustomDataPermissionHandler.registerProcessWhereExpressionListener(dataScope, this);
        }
    }
}
